import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/count_down_timer.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_rx/src/rx_typedefs/rx_typedefs.dart';

//京东同款样式，带倒计时的秒杀tabbar

///tabbar
class JingdongTabbar extends StatelessWidget {

  ///是否选中
  final bool selected;

  ///开始时间
  final String begintime;

  ///结束时间
  final String endtime;

  ///状态
  final int status;

  ///点击回调
  final Callback onClick;

  ///边框类型
  final int radiusType;
  const JingdongTabbar({super.key, required this.selected, required this.radiusType, required this.begintime, required this.endtime, required this.status, required this.onClick});

  @override
  Widget build(BuildContext context) {
    

    BorderRadiusGeometry leftRadius = const BorderRadius.only(
      bottomLeft: Radius.circular(18.0),
    );
    BorderRadiusGeometry rightRadius = const BorderRadius.only(
      bottomRight: Radius.circular(18.0),
    );

    BorderRadiusGeometry allRadius = const BorderRadius.only(
      bottomLeft: Radius.circular(18.0),
      bottomRight: Radius.circular(18.0),
    );

    late BorderRadiusGeometry? radius;

    switch (radiusType) {
      case 1:
        radius = leftRadius;
        break;
      case 2:
        radius = rightRadius;
        break;
      case 3:
        radius = allRadius;
        break;
      default:
        radius = null;
    }

    return BaseInteractive(
      onClick: onClick,
      childWidget: selected == false
          ? Container(
              alignment: Alignment.bottomCenter,
              child: Container(
                height: 48.h,
                color: Colors.white,
                alignment: Alignment.bottomCenter,
                child: Container(
                  decoration: BoxDecoration(
                    color: Tools.fromHex("#FF5960"),
                    borderRadius: radius,
                  ),
                  width: 90.w,
                  height: 48.h,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      status == 2
                          ? Container(
                              margin: EdgeInsets.only(left: 10.w),
                              child: CountDownTimer(
                                timeStamp: DateTime.parse(endtime).millisecondsSinceEpoch,
                                timeStyle: TimeStyle.hhmmss,
                                countDownStyle: CountDownStyle.box,
                                boxBackgroundColor: Tools.fromHex("#FFFFFF"),
                                style: setTextStyle(8, FontWeight.w700,
                                    Tools.fromHex("#FF5960")),
                                colonColor: Tools.fromHex("#FFFFFF"),
                              ),
                            )
                          : Text(begintime,
                              style: setTextStyle(12, FontWeight.w700,
                                  Tools.fromHex("#FFFFFF"))),
                      status == 2
                          ? Text("正在抢购",
                              style: setTextStyle(12, FontWeight.w400,
                                  Tools.fromHex("#FFFFFF")))
                          : Text("即将开始",
                              style: setTextStyle(12, FontWeight.w400,
                                  Tools.fromHex("#FFFFFF")))
                    ],
                  ),
                ),
              ),
            )
          : Container(
              decoration: const BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10.0),
                  topRight: Radius.circular(10.0),
                ),
              ),
              width: 125.w,
              height: 59.h,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    child: status == 2
                        ? Container(
                            margin: EdgeInsets.only(left: 10.w),
                            child: CountDownTimer(
                              timeStamp: DateTime.parse(endtime).millisecondsSinceEpoch,
                              timeStyle: TimeStyle.hhmmss,
                              countDownStyle: CountDownStyle.box,
                              boxBackgroundColor: Tools.fromHex("#333333"),
                              style: setTextStyle(14, FontWeight.w700,
                                  Tools.fromHex("#FFFFFF")),
                              colonColor: Colors.black,
                            ),
                          )
                        : Text(
                            begintime,
                            style:
                                setTextStyle(16, FontWeight.w700, Colors.black),
                          ),
                  ),
                  SizedBox(height: 5.w),
                  status == 2
                          ? Text("正在抢购",
                              style: setTextStyle(12, FontWeight.w400,
                                  Tools.fromHex("#F83F2D")))
                          : Text("即将开始",
                              style: setTextStyle(12, FontWeight.w400,
                                  Tools.fromHex("#F83F2D")))
                ],
              ),
            ),
    );
  }
}